package com.vybfi.pma.logging;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.Arrays;

@Aspect
@Component
public class ApplicationLoggerAspect {
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Pointcut("within(com.vybfi.pma.controllers..*)"+"|| within(com.vybfi.pma.dao..*)")
    public void definePackagePointcuts(){
    }

    @Before("definePackagePointcuts()")
    public void logBefore(JoinPoint joinPoint){
        log.debug("--------------cut(前)-----------------");
        log.debug(
                "{}.{}(),输入参数{}",
                joinPoint.getSignature().getDeclaringType(),
                joinPoint.getSignature().getName(),
                Arrays.toString(joinPoint.getArgs())
        );
        log.debug("--------------cut-----------------");
        log.debug("\n");
    }

    @After("definePackagePointcuts()")
    public void logAfter(JoinPoint joinPoint){
        log.debug("--------------cut(前)-----------------");
        log.debug(
                "{}.{}(),输入参数{}",
                joinPoint.getSignature().getDeclaringType(),
                joinPoint.getSignature().getName(),
                Arrays.toString(joinPoint.getArgs())
        );
        log.debug("--------------cut-----------------");
        log.debug("\n");
    }

}
